 <#include '/admin/header.html' >
<style>
.layui-form-pane .layui-input:focus, .layui-form-pane .layui-textarea:focus
	{
	border-radius: 2px;
	border-color: #01AAED !important;
}
</style>
<div class="main">
	<!--表单区域  -->
	<div class="main-top">
		<form id="addmodelForm" class="layui-form layui-form-pane" action=""
			enctype="multipart/form-data" style="padding-top: 10px">
			<div class="layui-form-item">
				<label class="layui-form-label">模型名称:</label>
				<div class="layui-input-block">
					<input type="text" value="${dataModel.china_name!''}"
						name="china_name" maxlength="60" dataType="string"
						lay-verify="required" autocomplete="off" class="layui-input"
						style="width: 20%;"> <input type="hidden" name="model_id"
						value="${dataModel.model_id }" id="modelid" />
				</div>
			</div>

			<div class="layui-form-item">
				<label class="layui-form-label">表名:</label>
				<div class="layui-input-block">
					<input type="text" value="${dataModel.english_name!''}"
						name="english_name" maxlength="22" size="40"
						onblur="validation(this)" lay-verify="required" autocomplete="off"
						class="layui-input" style="width: 20%;">
				</div>
			</div>

			<div class="layui-form-item">
				<label class="layui-form-label">备注</label>
				<div class="layui-input-block">
					<script id="editor" name="brief" type="text/plain"
						style="height: 200px; width: 99%;"></script>
				</div>
			</div>

			<div class="layui-form-item">
				<div class="layui-layer-btn layui-layer-btn-"
					style="padding: 8px 12px; z-index: 1000;">
					<a class="layui-layer-btn0" type="submit" lay-submit=""
						lay-filter="editModel">保存</a>
				</div>
			</div>
		</form>
	</div>

	<!-- 表格区域 -->
	<form id="fieldForm">
		<div class="table_control">
			<div class="table_opera">
				<button type="button" title="添加字段" id="addfield"
					class="layui-btn layui-btn-primary layui-btn-small">
					<i class="layui-icon">&#xe608;</i>
				</button>
			</div>
		</div>

		<div class="shadowBoxWhite tableDiv">
			<table id="fielddata" class="layui-table site-table table-hover"
				width="100%">
				<thead>
					<tr>
						<th width="10px"><input type='checkbox'
							class='btn-checkall fly-checkbox' id='selected-all'></th>
						<th>提示文字</th>
						<th>字段名</th>
						<th>排序</th>
						<th>修改</th>
						<th>删除</th>
					</tr>
				</thead>
			</table>
		</div>
	</form>
</div>

<!--js区域  -->
<script>
var table;
var index = parent.layer.getFrameIndex(window.name);

layui.use(['form', 'layedit', 'laydate'], function(){
    var form = layui.form()
        ,layer = layui.layer
        ,layedit = layui.layedit
        ,laydate = layui.laydate;


form.on('submit(editModel)', function(data){
	var options = {
		url : ctx+"/cms/admin/model/save-edit.do",
		type : "POST",
		dataType : 'json',
		success : function(result) {
			if (result.result == 1) {
				$.Loading.success(result.message);
				
			}
			if (result.result == 0) {
				$.Loading.error(result.message);
			}
		},
		error : function(e) {
			$.Loading.error("出现错误 ，请重试");
		}
	};
	$("#addmodelForm").ajaxSubmit(options);
	
	return false;
});

});


//富文本编辑器
var ue = UE.getEditor('editor');
$(function(){
	
	table = $('#fielddata').DataTable({
		"language": {
	        "url": "${staticserver}/media/zh_CN.txt"
	    },
	    "processing": true,
	    "serverSide": true,
	    "ordering": false,
	    "searching": false,
	    "lengthChange": false,
	    ajax: {
	        //指定数据源
	        type:"post",
	        url: '${ctx}/cms/admin/model/file-list-json.do?modelid=${dataModel.model_id }',
	    },
	    columns: [ //定义列
	               {"data": function (obj) {
	                   return '<input type="checkbox" name="goods_id" class="fly-checkbox" value=' + obj.field_id + '>';
	               }},
	        {data: "china_name"},
	        {data: "english_name"},
	        {data: "taxis"},
	        {data: function (obj) {
	        	return "<a class='layui-btn layui-btn-small layui-btn-normal' onclick='edit("+ obj.field_id + ")'>修改</a>";	
	       	}},
	       	{data: function (obj) {
	        	return "<a class='layui-btn layui-btn-small layui-btn-danger' onclick='del("+ obj.field_id+ ")'>删除</a>";
	       	}}
	     ]
	});
	
	
	//添加字段弹框
	$("#addfield").click(function(){
		var modelid=$("#modelid").val();
	   	 layer.open({
	            title:"添加字段",//标题
	            maxmin :true,//右上角可否放大缩小
	            type:2,//弹框的类型
	            shade: [0.3, '#000'],//黑色背景
	            offset: '10px',//弹框位置
	            shadeClose:false,//黑色背景是否可以点击关闭
	            content:'${ctx}/cms/admin/field/add.do?ajax=yes&modelid='+modelid,//内容的URL
	            area:['700px','450px'],//弹框大小
	            scrollbar: true//是否允许浏览器出现滚动条
	        });
	});
});
//删除
function del(field_id) {
	if (!confirm("确认要删除吗？")) {
		return;
	}
	var options = {
		url : ctx + "/cms/admin/field/delete.do?field_id=" + field_id,
		type : "POST",
		dataType : 'json',
		success : function(result) {
			if (result.result == 1) {
				$.Loading.success(result.message);
			    table.ajax.url("${ctx}/cms/admin/model/file-list-json.do?modelid=${dataModel.model_id }")
						.load();
				 				
			}
			if (result.result == 0) {
				$.Loading.error(result.message);
			}
		}
	};
	$("#fieldForm").ajaxSubmit(options);
}
//修改字段弹框
	 function edit(fieldid){
		 var modelid=$("#modelid").val();
	　　	 layer.open({
	            title:"修改字段",//标题
	            maxmin :true,//右上角可否放大缩小
	            type:2,//弹框的类型
	            shade: [0.3, '#000'],//黑色背景
	            offset: '10px',//弹框位置
	            shadeClose:false,//黑色背景是否可以点击关闭
	            content:'${ctx}/cms/admin/field/edit.do?modelid='+modelid+'&fieldid='+fieldid+'&ajax=yes',//内容的URL
	            area:['700px','450px'],//弹框大小
	            scrollbar: true//是否允许浏览器出现滚动条
	        });
	 }

</script>
<#include '/admin/footer.html' >
